package com.common.config;

import com.mongodb.Mongo;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.core.MongoClientFactoryBean;
import org.springframework.data.mongodb.core.MongoFactoryBean;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;

/**
 * @classDescription:
 * @author:xiayingjie
 * @createTime:16/8/16
 */
//@Configuration
//扫描dao，mongodb 自动生成
//@EnableMongoRepositories(basePackages = "")
public class MongoConfig {

    //配置mongo的环境 负责连接mongodb数据库
    @Bean
    public MongoClientFactoryBean mongo(){
        MongoClientFactoryBean mongo=new MongoClientFactoryBean();
        mongo.setHost("localhost");
       // mongo.setPort();
        return mongo;
    }
    //配置mongodb的数据库模板 repository底层直接使用了它
    @Bean
    public MongoOperations mongoOperations(Mongo mongo){
        return new MongoTemplate(mongo,"test");
    }

}
